<template>
  <view>
    <view>
      <uni-notice-bar :speed="50" scrollable showIcon :text="`以下为医学检查必要问询，请根据实际情况填写。标注的红色项为必填项`" />
    </view>
    <view>
      <scroll-view style="height: 80vh;" :scroll-y="true">
        <uni-forms ref="medicalHistoryInfoForm" :labelWidth="200" labelPosition="top" errShowType="toast" border
          :model="medicalHistoryInfo">
          <!-- (一)宫颈癌病史情况 -->
          <uni-card margin="5px" padding="0" title="(一)宫颈癌病史情况">
            <!-- 症状 -->
            <uni-card margin="10px 0" padding="0" title="症状">
              <uni-grid :column="2" :showBorder="false" :square="false" :highlight="false">
                <uni-grid-item>
                  <uni-forms-item label="性交出血">
                    <radio-group @change="(e) => onRadioChange(e, 'intercourse')">
                      <label v-for="(item, index) in noneRange" :key="index" style="margin-right: 15px;">
                        <radio color="#2979ff" :value="item.value"
                          :checked="item.value === medicalHistoryInfo.intercourse" />
                        <text>{{ item.text }}</text>
                      </label>
                    </radio-group>
                  </uni-forms-item>
                </uni-grid-item>
                <uni-grid-item>
                  <uni-forms-item label="白带异常">
                    <radio-group @change="(e) => onRadioChange(e, 'leucorrhea')">
                      <label v-for="(item, index) in noneRange" :key="index" style="margin-right: 15px;">
                        <radio color="#2979ff" :value="item.value"
                          :checked="item.value === medicalHistoryInfo.leucorrhea" />
                        <text>{{ item.text }}</text>
                      </label>
                    </radio-group>
                  </uni-forms-item>
                </uni-grid-item>
              </uni-grid>
            </uni-card>
            <!-- 月经情况 -->
            <uni-card margin="10px 0" padding="0" title="月经情况">
              <uni-forms-item required label="周期">
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 5px 0 0;" class="test-pre">持续时间</text>
                  <uni-easyinput class="input-field" type="number" v-model="medicalHistoryInfo.day1" />
                  <text style="margin: 5px 5px;">~</text>
                  <uni-easyinput class="input-field" type="number" v-model="medicalHistoryInfo.day3" />
                  <text style="margin: 6px 0 0 5px;">天</text>
                </view>
                <view style="width: 100%;margin-top: 5px;" class="input-row">
                  <text style="margin: 6px 5px 0 0;" class="test-pre">周期</text>
                  <uni-easyinput class="input-field" type="number" v-model="medicalHistoryInfo.day2" />
                  <text style="margin: 5px 5px;">~</text>
                  <uni-easyinput class="input-field" type="number" v-model="medicalHistoryInfo.day4" />
                  <text style="margin: 6px 0 0 5px;">天</text>
                </view>
              </uni-forms-item>
              <uni-forms-item>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 5px 0 0;" class="test-pre">月经初潮年龄</text>
                  <uni-easyinput class="input-field" type="number" v-model="medicalHistoryInfo.yuechu" />
                  <text style="margin: 6px 0 0 5px;">岁</text>
                </view>
              </uni-forms-item>
              <uni-forms-item label="末次月经">
                <uni-datetime-picker type="date" :end="lastMenstrualCycle" v-model="medicalHistoryInfo.menstruation" />
              </uni-forms-item>
              <uni-forms-item label="绝经">
                <radio-group @change="onMenopauseChange">
                  <label v-for="(item, index) in menopauseRange" :key="index">
                    <view style="width: 100%;margin-bottom: 5px;" class="input-row">
                      <radio style="margin: 5px 0 0 0;" color="#2979ff" :value="item.value"
                        :checked="item.value === medicalHistoryInfo.menopause" />
                      <text style="margin: 6px 10px 0 0;">{{ item.text }}</text>

                      <text v-if="item.value === '是'" style="margin: 6px 0 0 0;">绝经年龄：</text>
                      <uni-easyinput v-if="item.value === '是'" class="input-field"
                        :disabled="medicalHistoryInfo.menopause !== '是'" type="number"
                        v-model="medicalHistoryInfo.menopause2" />
                      <text v-if="item.value === '是'" style="margin: 6px 0 0 5px;">岁</text>
                    </view>
                  </label>
                </radio-group>
              </uni-forms-item>
            </uni-card>
            <!-- 目前使用避孕方法 -->
            <uni-card margin="10px 0" padding="0">
              <template v-slot:title>
                <view class="card__header">
                  <view class="card__header-box">
                    <view class="card__header-content">
                      <text class="card__header-content-title card__header-content-title-pre">目前使用避孕方法</text>
                    </view>
                  </view>
                </view>
              </template>
              <uni-forms-item>
                <radio-group @change="onContraceptiveChange">
                  <label v-for="(item, index) in contraceptionRange" :key="index">
                    <view style="width: 100%;margin-bottom: 5px;" class="input-row">
                      <radio style="margin: 5px 0 0 0;" color="#2979ff" :value="item.value"
                        :checked="item.value === medicalHistoryInfo.contraceptive" />
                      <text style="width: 100px;margin: 6px 5px 0 0;">{{ item.text }}</text>

                      <uni-easyinput v-if="item.value === '避孕药'" class="input-field"
                        :disabled="medicalHistoryInfo.contraceptive !== '避孕药'" type="number"
                        v-model="medicalHistoryInfo.contraceptive1" />

                      <uni-easyinput v-if="item.value === '宫内节育器'" class="input-field"
                        :disabled="medicalHistoryInfo.contraceptive !== '宫内节育器'" type="number"
                        v-model="medicalHistoryInfo.contraceptive2" />
                      <text v-if="item.value === '避孕药' || item.value === '宫内节育器'" style="margin: 6px 0 0 5px;">年</text>

                      <uni-easyinput v-if="item.value === '其他避孕方法'" class="input-field"
                        :disabled="medicalHistoryInfo.contraceptive !== '其他避孕方法'"
                        v-model="medicalHistoryInfo.contraceptive3" />
                    </view>
                  </label>
                </radio-group>
              </uni-forms-item>
            </uni-card>
            <!-- 孕产史 -->
            <uni-card margin="10px 0" padding="0" title="孕产史">
              <uni-forms-item>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 5px 0 0;" class="test-pre">孕次</text>
                  <uni-easyinput style="margin-right: 5px;" type="number" v-model="medicalHistoryInfo.yunci" />
                </view>
              </uni-forms-item>
              <uni-forms-item>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 5px 0 0;" class="test-pre">分娩次</text>
                  <uni-easyinput type="number" v-model="medicalHistoryInfo.fenmianci" />
                </view>
              </uni-forms-item>
              <uni-grid :column="2" :showBorder="false" :square="false" :highlight="false">
                <uni-grid-item>
                  <uni-forms-item label="是否生产过">
                    <radio-group @change="(e) => onRadioChange(e, 'sheng')">
                      <label v-for="(item, index) in whetherRange" :key="index" style="margin-right: 15px;">
                        <radio color="#2979ff" :value="item.value" :checked="item.value === medicalHistoryInfo.sheng" />
                        <text>{{ item.text }}</text>
                      </label>
                    </radio-group>
                  </uni-forms-item>
                </uni-grid-item>
                <uni-grid-item>
                  <uni-forms-item label="是否哺乳">
                    <radio-group @change="(e) => onRadioChange(e, 'bu')">
                      <label v-for="(item, index) in whetherRange" :key="index" style="margin-right: 15px;">
                        <radio color="#2979ff" :value="item.value" :checked="item.value === medicalHistoryInfo.bu" />
                        <text>{{ item.text }}</text>
                      </label>
                    </radio-group>
                  </uni-forms-item>
                </uni-grid-item>
              </uni-grid>
              <uni-forms-item>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 5px 0 0;">初产年龄</text>
                  <uni-easyinput class="input-field" type="number" v-model="medicalHistoryInfo.chu" />
                  <text style="margin: 6px 0 0 5px;">岁</text>
                </view>
              </uni-forms-item>
            </uni-card>
            <!-- 既往接受过宫颈癌检查 -->
            <uni-card margin="10px 0" padding="0">
              <template v-slot:title>
                <view class="card__header">
                  <view class="card__header-box">
                    <view class="card__header-content">
                      <text class="card__header-content-title">既往接受过宫颈癌检查</text>
                    </view>
                  </view>
                </view>
              </template>
              <uni-forms-item>
                <radio-group>
                  <label v-for="(item, index) in acceptRange" :key="index" style="margin-right: 15px;">
                    <radio color="#2979ff" :value="item.value" :checked="item.value === medicalHistoryInfo.accept" />
                    <text>{{ item.text }}</text>
                  </label>
                </radio-group>
              </uni-forms-item>
            </uni-card>
            <!-- 既往史 -->
            <uni-card margin="10px 0" padding="0" title="既往史">
              <uni-forms-item required label="宫颈细胞学异常">
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 5px 0 0;">持续</text>
                  <uni-easyinput class="input-field" type="number" v-model="medicalHistoryInfo.cytology" />
                  <text style="margin: 6px 0 0 5px;">月</text>
                </view>
                <view style="width: 100%;margin-top: 5px;" class="input-row">
                  <text style="margin: 6px 0 0 0;">结果：</text>
                  <uni-easyinput class="input-field" v-model="medicalHistoryInfo.cytology2" />
                </view>
              </uni-forms-item>
              <uni-forms-item required label="HPV检查阳性">
                <radio-group @change="(e) => onRadioChange(e, 'hpv')">
                  <label v-for="(item, index) in noneRange" :key="index" style="margin-right: 15px;">
                    <radio color="#2979ff" :value="item.value" :checked="item.value === medicalHistoryInfo.hpv" />
                    <text>{{ item.text }}</text>
                  </label>
                </radio-group>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 0 0 0;">请说明原因：</text>
                  <uni-easyinput class="input-field" :disabled="medicalHistoryInfo.hpv !== '有'"
                    v-model="medicalHistoryInfo.hpv2" />
                </view>
              </uni-forms-item>
              <uni-forms-item label="CIN">
                <radio-group @change="(e) => onRadioChange(e, 'cin')">
                  <label v-for="(item, index) in noneRange" :key="index" style="margin-right: 15px;">
                    <radio color="#2979ff" :value="item.value" :checked="item.value === medicalHistoryInfo.cin" />
                    <text>{{ item.text }}</text>
                  </label>
                </radio-group>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 0 0 0;">请说明原因：</text>
                  <uni-easyinput class="input-field" :disabled="medicalHistoryInfo.cin !== '有'"
                    v-model="medicalHistoryInfo.cin2" />
                </view>
              </uni-forms-item>
              <uni-forms-item label="宫颈癌">
                <radio-group @change="(e) => onRadioChange(e, 'cervical')">
                  <label v-for="(item, index) in noneRange" :key="index" style="margin-right: 15px;">
                    <radio color="#2979ff" :value="item.value" :checked="item.value === medicalHistoryInfo.cervical" />
                    <text>{{ item.text }}</text>
                  </label>
                </radio-group>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 0 0 0;">请说明原因：</text>
                  <uni-easyinput class="input-field" :disabled="medicalHistoryInfo.cervical !== '有'"
                    v-model="medicalHistoryInfo.cervical2" />
                </view>
              </uni-forms-item>
              <uni-forms-item label="生殖道感染">
                <radio-group @change="(e) => onRadioChange(e, 'reproductive')">
                  <label v-for="(item, index) in noneRange" :key="index" style="margin-right: 15px;">
                    <radio color="#2979ff" :value="item.value"
                      :checked="item.value === medicalHistoryInfo.reproductive" />
                    <text>{{ item.text }}</text>
                  </label>
                </radio-group>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 0 0 0;">请说明原因：</text>
                  <uni-easyinput class="input-field" :disabled="medicalHistoryInfo.reproductive !== '有'"
                    v-model="medicalHistoryInfo.reproductive2" />
                </view>
              </uni-forms-item>
              <uni-forms-item label="其他肿瘤">
                <radio-group @change="(e) => onRadioChange(e, 'other')">
                  <label v-for="(item, index) in noneRange" :key="index" style="margin-right: 15px;">
                    <radio color="#2979ff" :value="item.value" :checked="item.value === medicalHistoryInfo.other" />
                    <text>{{ item.text }}</text>
                  </label>
                </radio-group>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 0 0 0;">请说明原因：</text>
                  <uni-easyinput class="input-field" :disabled="medicalHistoryInfo.other !== '有'"
                    v-model="medicalHistoryInfo.other2" />
                </view>
              </uni-forms-item>
            </uni-card>
            <!-- 家族肿瘤史 -->
            <uni-card margin="10px 0" padding="0" title="家族肿瘤史">
              <uni-forms-item>
                <radio-group @change="(e) => onRadioChange(e, 'familyname')">
                  <label v-for="(item, index) in noneRange" :key="index" style="margin-right: 15px;">
                    <radio color="#2979ff" :value="item.value"
                      :checked="item.value === medicalHistoryInfo.familyname" />
                    <text>{{ item.text }}</text>
                  </label>
                </radio-group>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 5px 0 0;">请注明：疾病名称</text>
                  <uni-easyinput class="input-field" :disabled="medicalHistoryInfo.familyname !== '有'"
                    v-model="medicalHistoryInfo.familyname2" />
                </view>
              </uni-forms-item>
              <uni-forms-item label="患者家属与自己关系">
                <radio-group @change="(e) => onRadioChange(e, 'familylevel')">
                  <label v-for="(item, index) in familylevelRange" :key="index">
                    <view style="margin-bottom: 5px;">
                      <radio :disabled="medicalHistoryInfo.familyname === '无'" color="#2979ff" :value="item.value"
                        :checked="item.value === medicalHistoryInfo.familylevel" />
                      <text>{{ item.text }}</text>
                    </view>
                  </label>
                </radio-group>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 0 0 0;">其他，请注明：</text>
                  <uni-easyinput class="input-field" :disabled="medicalHistoryInfo.familylevel !== '其他'"
                    v-model="medicalHistoryInfo.familylevel2" />
                </view>
              </uni-forms-item>
            </uni-card>
          </uni-card>
          <!-- (二)乳腺癌病史情况 -->
          <uni-card margin="5px" padding="0" title="(二)乳腺癌病史情况">
            <!-- 过去是否接受过乳腺检查 -->
            <uni-card margin="10px 0" padding="0" title="过去是否接受过乳腺检查">
              <uni-forms-item>
                <radio-group @change="onJianChange">
                  <label v-for="(item, index) in whetherRange" :key="index" style="margin-right: 15px;">
                    <radio color="#2979ff" :value="item.value" :checked="item.value === medicalHistoryInfo.jian" />
                    <text>{{ item.text }}</text>
                  </label>
                </radio-group>
              </uni-forms-item>
              <uni-forms-item>
                <view style="width: 100%;" class="input-row">
                  <text style="margin: 6px 0 0 0;">(1)最近一次检验时间：</text>
                  <uni-data-picker style="width: 100px;" :readonly="medicalHistoryInfo.jian !== '是'" :clearIcon="false"
                    :localdata="jian1Range" v-model="medicalHistoryInfo.jian1" />
                  <text style="margin: 6px 0 0 5px;">年</text>
                </view>
              </uni-forms-item>
              <uni-forms-item label="(2)检查内容：(多选)">
                <checkbox-group @change="onJian2Change">
                  <label v-for="(item, index) in jian2Range" :key="index" style="margin-right: 15px;">
                    <checkbox style="margin: 5px 0 0 0;" :disabled="medicalHistoryInfo.jian !== '是'" :value="item.value"
                      :checked="medicalHistoryInfo.jian2.includes(item.value)" />
                    <text>{{ item.text }}</text>
                  </label>
                  <label>
                    <view>
                      <checkbox style="margin: 5px 0 0 0;" :disabled="medicalHistoryInfo.jian !== '是'" value="其他"
                        :checked="medicalHistoryInfo.jian2.includes('其他')" />
                      <text style="margin: 6px 10px 0 0;">其他</text>
                    </view>
                  </label>
                </checkbox-group>
                <view style="width: 100%;margin-top: 5px;" class="input-row">
                  <text style="margin: 6px 0 0 0;">请注明：</text>
                  <uni-easyinput class="input-field" :disabled="!medicalHistoryInfo.jian2.includes('其他')"
                    v-model="medicalHistoryInfo.jian3" />
                </view>
              </uni-forms-item>
            </uni-card>
            <!-- 既往史 -->
            <uni-card margin="10px 0" padding="0" title="既往史">
              <uni-forms-item label="乳腺手术或活检史">
                <radio-group @change="onJi1Change">
                  <label v-for="(item, index) in noneRange" :key="index">
                    <view style="width: 100%;margin-bottom: 5px;" class="input-row">
                      <radio style="margin: 5px 0 0 0;" color="#2979ff" :value="item.value"
                        :checked="item.value === medicalHistoryInfo.ji1" />
                      <text style="margin: 6px 10px 0 0;">{{ item.text }}</text>

                      <uni-easyinput v-if="item.value === '有'" class="input-field"
                        :disabled="medicalHistoryInfo.ji1 !== '有'" type="number" v-model="medicalHistoryInfo.ji2" />
                      <text v-if="item.value === '有'" style="margin: 6px 0 0 5px;">次</text>
                    </view>
                  </label>
                </radio-group>
                <view style="width: 100%;margin-top: 5px;" class="input-row">
                  <text>注明病历结果：</text>
                  <radio-group class="input-field" @change="(e) => onRadioChange(e, 'ji3')">
                    <label v-for="(item, index) in ji3Range" :key="index" style="margin-right: 15px;">
                      <radio :disabled="medicalHistoryInfo.ji1 !== '有'" color="#2979ff" :value="item.value"
                        :checked="item.value === medicalHistoryInfo.ji3" />
                      <text>{{ item.text }}</text>
                    </label>
                  </radio-group>
                </view>
              </uni-forms-item>
              <uni-forms-item label="激素替代治疗史">
                <radio-group @change="(e) => onRadioChange(e, 'su1')">
                  <label v-for="(item, index) in noneRange" :key="index" style="margin-right: 15px;">
                    <radio color="#2979ff" :value="item.value" :checked="item.value === medicalHistoryInfo.su1" />
                    <text>{{ item.text }}</text>
                  </label>
                </radio-group>
                <view style="margin-top: 5px;">
                  <text>注明用药时间：</text>
                </view>
                <view style="width: 100%;margin-top: 5px;" class="input-row">
                  <uni-easyinput class="input-field" :disabled="medicalHistoryInfo.su1 != '有'" type="number"
                    v-model="medicalHistoryInfo.su2" />
                  <text style="margin: 6px 0 0 5px;">年(不足1一年按1年计算)</text>
                </view>
              </uni-forms-item>
            </uni-card>
            <!-- 二级以内亲属乳腺癌或卵巢癌家族史 -->
            <uni-card margin="10px 0" padding="0" title="二级以内亲属乳腺癌或卵巢癌家族史">
              <uni-forms-item label="乳腺癌">
                <radio-group @change="onRfn1Change">
                  <label v-for="(item, index) in rfn1Range" :key="index">
                    <view v-if="item.value === '一级亲属(父母、子女、亲兄弟、姐妹(同父母))'">
                      <text>有，患者家属与自己关系：</text>
                    </view>
                    <view style="width: 100%;margin-bottom: 5px;" class="input-row">
                      <radio style="margin: 5px 0 0 0;" color="#2979ff" :value="item.value"
                        :checked="item.value === medicalHistoryInfo.rfn1" />
                      <text style="margin: 6px 10px 0 0;">{{ item.text }}</text>

                      <text v-if="item.value === '其他'" style="margin: 6px 0 0 0;">请注明：</text>
                      <uni-easyinput v-if="item.value === '其他'" class="input-field"
                        :disabled="medicalHistoryInfo.rfn1 !== '其他'" v-model="medicalHistoryInfo.rfn2" />
                    </view>
                  </label>
                </radio-group>
              </uni-forms-item>
              <uni-forms-item label="卵巢癌">
                <radio-group @change="onLfn1Change">
                  <label v-for="(item, index) in lfn1Range" :key="index">
                    <view v-if="item.value === '一级亲属(父母、子女、亲兄弟、姐妹(同父母))'">
                      <text>有，患者家属与自己关系：</text>
                    </view>
                    <view style="width: 100%;margin-bottom: 5px;" class="input-row">
                      <radio style="margin: 5px 0 0 0;" color="#2979ff" :value="item.value"
                        :checked="item.value === medicalHistoryInfo.lfn1" />
                      <text style="margin: 6px 10px 0 0;">{{ item.text }}</text>

                      <text v-if="item.value === '其他'" style="margin: 6px 0 0 0;">请注明：</text>
                      <uni-easyinput v-if="item.value === '其他'" class="input-field"
                        :disabled="medicalHistoryInfo.lfn1 !== '其他'" v-model="medicalHistoryInfo.lfn2" />
                    </view>
                  </label>
                </radio-group>
              </uni-forms-item>
            </uni-card>
          </uni-card>
        </uni-forms>
      </scroll-view>
    </view>
    <view class="text-center" style="padding-top: 15rpx;">
      <button class="btn-df text-white" @tap="savePatientBasicInfo">保存</button>
    </view>
  </view>
</template>

<script setup>
  const noneRange = ref([{
    text: '无',
    value: '无'
  }, {
    text: '有',
    value: '有'
  }])
  const whetherRange = ref([{
    text: '否',
    value: '否'
  }, {
    text: '是',
    value: '是'
  }])
  // 末次月经
  const lastMenstrualCycle = ref(Date.now())
  // 绝经
  const menopauseRange = ref([{
    text: '否',
    value: '否'
  }, {
    text: '是',
    value: '是'
  }, {
    text: '不确定',
    value: '不确定'
  }])
  // 目前使用避孕方法
  const contraceptionRange = ref([{
    text: '未避孕',
    value: '未避孕'
  }, {
    text: '避孕套',
    value: '避孕套'
  }, {
    text: '避孕药',
    value: '避孕药'
  }, {
    text: '宫内节育器',
    value: '宫内节育器'
  }, {
    text: '其他避孕方法',
    value: '其他避孕方法'
  }])
  // 既往接受过宫颈癌检查
  const acceptRange = ref([{
    text: '三年内',
    value: '三年内'
  }, {
    text: '三年以上',
    value: '三年以上'
  }, {
    text: '否',
    value: '否'
  }])
  // 患者家属与自己关系
  const familylevelRange = ref([{
    text: '一级属性(父母、子女、亲兄弟姐妹(同父母))',
    value: '一级属性(父母、子女、亲兄弟姐妹(同父母))'
  }, {
    text: '其他',
    value: '其他'
  }])
  // 检验时间 年份
  const jian1Range = ref([])
  // 检查内容
  const jian2Range = ref([{
    text: '手诊',
    value: '手诊'
  }, {
    text: '超声',
    value: '超声'
  }, {
    text: 'X线',
    value: 'X线'
  }, {
    text: '不详',
    value: '不详'
  }])
  // 乳腺手术或活检史病历结果
  const ji3Range = ref([{
    text: '良性',
    value: '良性'
  }, {
    text: '恶性',
    value: '恶性'
  }])
  // 乳腺癌
  const rfn1Range = ref([{
    text: '无',
    value: '无'
  }, {
    text: '一级亲属(父母、子女、亲兄弟、姐妹(同父母))',
    value: '一级亲属(父母、子女、亲兄弟、姐妹(同父母))'
  }, {
    text: '其他',
    value: '其他'
  }])
  // 卵巢癌
  const lfn1Range = ref([{
    text: '无',
    value: '无'
  }, {
    text: '一级亲属(父母、子女、亲兄弟、姐妹(同父母))',
    value: '一级亲属(父母、子女、亲兄弟、姐妹(同父母))'
  }, {
    text: '其他',
    value: '其他'
  }])

  // 患者信息
  const patientInfo = ref({})
  // 病史信息
  const medicalHistoryInfo = ref({
    intercourse: "无", // 性交出血ok//
    leucorrhea: "无", // 白带异常ok//
    sheng: "否", // 是否生产过
    day1: null, //周期ok//
    day2: null, //周期ok//
    day3: null, // 持续时间2
    day4: null, // 周期2
    menstruation: null, // 末次月经ok//
    menopause: "否", // 绝经ok//
    menopause2: null, //ok//
    contraceptive: null, // 避孕方法ok//
    contraceptive1: null, // 避孕药年
    contraceptive2: null, // 宫内节育器年
    contraceptive3: null, // 其他避孕方法
    yunci: null, // 孕次//ok//
    fenmianci: null, // 分娩次ok//
    accept: "否", // 既往是否接受过宫颈癌检查ok//
    cytology: null, // 宫颈细胞学结果异常ok//
    cytology2: null, //ok//
    hpv: "无", // HPV检查阳性ok//
    hpv2: null, //ok//
    cin: "无", // CIN ok//
    cin2: null, //ok//
    cervical: "无", // 宫颈癌ok//
    cervical2: null, //ok//
    reproductive: "无", // 生殖道感染//ok
    reproductive2: null, //ok//
    other: "无", // 其他肿瘤ok//
    other2: null, //ok//
    familyname: "无", //ok//
    familyName2: null, // 家族肿瘤史疾病名称ok//
    familylevel: null, // 家族肿瘤史一级亲属ok//
    familylevel2: null, //ok//
    checkOrg: null, //--------
    checkUser: null, //------
    checkDate: null, //------
    patientId: null, //ok//
    // id: null, //ok//
    yuechu: null, //ok//
    chu: null, //ok//
    bu: "否", //ok//
    jian: "否", //ok//
    jian1: null, //ok//
    jian2: [], //ok?????//
    jian3: null, //ok//
    ji1: "无", //ok//
    ji2: null, //ok//
    ji3: null, //ok//
    rfn1: "无", //ok//
    rfn2: null, //ok//
    lfn1: "无", //ok//
    lfn2: null, //ok//
    su1: "无", //ok//
    su2: null, //ok//
  })
  const medicalHistoryInfoForm = ref()

  onLoad((options) => {
    let item = !util.judgeNull(options) ? JSON.parse(decodeURIComponent(options.item)) : {};
    patientInfo.value = item;
  })

  const onRadioChange = (e, field) => {
    medicalHistoryInfo.value[field] = e.detail.value;
    if (medicalHistoryInfo.value.familyname === '无') {
      medicalHistoryInfo.value.familylevel = null;
      medicalHistoryInfo.value.familylevel2 = null;
    }
    if (medicalHistoryInfo.value.su1 === '无') {
      medicalHistoryInfo.value.su2 = null;
    }
  }

  const onMenopauseChange = (e) => {
    medicalHistoryInfo.value.menopause = e.detail.value;
    if (e.detail.value !== '是') {
      medicalHistoryInfo.value.menopause2 = null;
    }
  }

  const onContraceptiveChange = (e) => {
    medicalHistoryInfo.value.contraceptive = e.detail.value;
    switch (e.detail.value) {
      case '避孕药':
        medicalHistoryInfo.value.contraceptive2 = null;
        medicalHistoryInfo.value.contraceptive3 = null;
        break;
      case '宫内节育器':
        medicalHistoryInfo.value.contraceptive1 = null;
        medicalHistoryInfo.value.contraceptive3 = null;
        break;
      case '其他避孕方法':
        medicalHistoryInfo.value.contraceptive1 = null;
        medicalHistoryInfo.value.contraceptive2 = null;
        break;
      default:
        medicalHistoryInfo.value.contraceptive1 = null;
        medicalHistoryInfo.value.contraceptive2 = null;
        medicalHistoryInfo.value.contraceptive3 = null;
    }
  }

  const onJianChange = (e) => {
    medicalHistoryInfo.value.jian = e.detail.value;
    if (e.detail.value !== '是') {
      medicalHistoryInfo.value.jian1 = null;
      medicalHistoryInfo.value.jian2 = [];
      medicalHistoryInfo.value.jian3 = null;
    } else {
      let yearList = [];
      let currentYear = new Date().getFullYear();
      for (let i = 20; i >= 0; i--) {
        yearList.push({
          text: currentYear - i,
          value: currentYear - i,
        });
      }
      jian1Range.value = yearList;
    }
  }
  const onJian2Change = (e) => {
    medicalHistoryInfo.value.jian2 = e.detail.value || [];
    if (!e.detail.value.includes('其他')) {
      medicalHistoryInfo.value.jian3 = null;
    }
  }

  const onJi1Change = (e) => {
    medicalHistoryInfo.value.ji1 = e.detail.value;
    if (e.detail.value !== '有') {
      medicalHistoryInfo.value.ji2 = null;
      medicalHistoryInfo.value.ji3 = null;
    }
  }

  const onRfn1Change = (e) => {
    medicalHistoryInfo.value.rfn1 = e.detail.value;
    if (e.detail.value !== '其他') {
      medicalHistoryInfo.value.rfn2 = null;
    }
  }

  const onLfn1Change = (e) => {
    medicalHistoryInfo.value.lfn1 = e.detail.value;
    if (e.detail.value !== '其他') {
      medicalHistoryInfo.value.lfn2 = null;
    }
  }

  const showErrToast = (errorMessage) => {
    uni.showToast({
      title: errorMessage || '校验错误',
      icon: 'none',
      duration: 2000
    })
  }

  // 保存病人基本信息
  const savePatientBasicInfo = () => {
    // 月经情况 周期 持续时间 day1
    if (util.judgeNull(medicalHistoryInfo.value.day1) || util.judgeNull(medicalHistoryInfo.value.day3) ||
      util.judgeNull(medicalHistoryInfo.value.day2) || util.judgeNull(medicalHistoryInfo.value.day4)) {
      showErrToast('请填写月经情况的周期必填项')
      return;
    }
    // 月经初潮年龄
    if (util.judgeNull(medicalHistoryInfo.value.yuechu)) {
      showErrToast('请填写月经初潮年龄')
      return;
    }
    // 末次月经
    // if (util.judgeNull(medicalHistoryInfo.value.menstruation)) {
    //   showErrToast()
    //   return;
    // }
    // 目前使用避孕方法
    if (util.judgeNull(medicalHistoryInfo.value.contraceptive)) {
      showErrToast('请选择目前使用的避孕方法')
      return;
    }
    // 孕次
    if (util.judgeNull(medicalHistoryInfo.value.yunci) || medicalHistoryInfo.value.yunci !== '0') {
      showErrToast('请填写孕次')
      return;
    }
    // 分娩次
    if (util.judgeNull(medicalHistoryInfo.value.fenmianci) || medicalHistoryInfo.value.fenmianci !== '0') {
      showErrToast('请填写分娩次')
      return;
    }
    console.log(medicalHistoryInfo.value);
    // medicalHistoryInfoForm.value.validate().then(res => {
    //   console.log('validate success ==》', res);
    //   let param = {
    //     ...medicalHistoryInfo.value,
    //   }
    //   http.post('/interface/savePatientInfo', {
    //     ...res,
    //   }).then((res) => {
    //     if (res.success) {
    //     }
    //   })
    // }).catch(err => {
    //   console.log('err', err);
    // })
  }
</script>

<style scoped lang="scss">
  @use './medicalHistory.scss';
</style>
